package com.huawei.appgallery.search.ui.card;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.huawei.appgallery.foundation.card.base.bean.KeywordInfo;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.MultiLineLabelLayout;
import com.huawei.appgallery.search.ui.cardbean.HistoryToggleCardBean;
import java.util.List;
import o.cgz;
import o.chy;
import o.cuv.a;
import o.cuv.b;
import o.cuv.e;
import o.cuv.f;
import o.cvk;
import o.ContentManager;
import o.CollectCheck;
import o.evx;

public class HistoryToggleCard extends BaseDistCard {
    private TextView ʻ;
    private MultiLineLabelLayout ʼ;
    private View ʽ;
    private LayoutInflater ˋ;
    private List<KeywordInfo> ˏॱ = null;
    private OnClickListener ͺ = new evx(this) {
        final /* synthetic */ HistoryToggleCard ॱ;

        {
            this.ॱ = r1;
        }

        public void ˋ(View view) {
            if (this.ॱ.ʼॱ instanceof Activity) {
                cvk.ॱ().ˊ((Activity) this.ॱ.ʼॱ);
                if (!CollectCheck.isEmpty(this.ॱ.ˏॱ)) {
                    this.ॱ.ˏॱ.clear();
                }
                this.ॱ.ʽ.setVisibility(8);
                this.ॱ.ʼ.setVisibility(8);
                this.ॱ.ॱॱ.setText("");
                this.ॱ.ʻ.setText("");
                this.ॱ.ˋ();
            }
        }
    };
    private chy ॱˊ;
    private TextView ॱॱ;
    private View ᐝ;

    public HistoryToggleCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        this.ᐝ = view;
        this.ˋ = (LayoutInflater) view.getContext().getSystemService("layout_inflater");
        this.ʼ = (MultiLineLabelLayout) view.findViewById(b.ʼॱ);
        this.ʽ = view.findViewById(b.ﾟ);
        this.ॱॱ = (TextView) view.findViewById(b.ʾ);
        this.ʻ = (TextView) view.findViewById(b.ॱᐝ);
        this.ʻ.setOnClickListener(this.ͺ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        HistoryToggleCardBean historyToggleCardBean = (HistoryToggleCardBean) cardBean;
        this.ˏॱ = cvk.ॱ().ˎ((Activity) this.ʼॱ);
        historyToggleCardBean.ˎ(this.ˏॱ);
        this.ʼ.removeAllViews();
        if (CollectCheck.isEmpty(this.ˏॱ)) {
            this.ʽ.setVisibility(8);
            this.ॱॱ.setText("");
            this.ʻ.setText("");
            return;
        }
        this.ʽ.setVisibility(0);
        this.ॱॱ.setText(f.ˋॱ);
        this.ʻ.setText(f.ˏॱ);
        this.ʼ.ˏ = (int) ContentManager.getInstant().getContext().getResources().getDimension(a.ॱॱ);
        ˋ(this.ʼ, this.ˏॱ);
    }

    private void ˋ(MultiLineLabelLayout multiLineLabelLayout, List<KeywordInfo> list) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            View ˏ = ˏ((KeywordInfo) list.get(i));
            ˏ.setTag(Integer.valueOf(i));
            ˏ.setOnClickListener(new evx(this) {
                final /* synthetic */ HistoryToggleCard ॱ;

                {
                    this.ॱ = r1;
                }

                public void ˋ(View view) {
                    if (view != null && (this.ॱ.ˌ() instanceof HistoryToggleCardBean)) {
                        ((HistoryToggleCardBean) this.ॱ.ˌ()).ʽ(((Integer) view.getTag()).intValue());
                        this.ॱ.ॱˊ.ˏ(7, this.ॱ);
                    }
                }
            });
            multiLineLabelLayout.addView(ˏ);
        }
    }

    private View ˏ(KeywordInfo keywordInfo) {
        View inflate = this.ˋ.inflate(e.ͺ, null);
        inflate.setLayoutParams(ˋ(inflate));
        ToggleButton toggleButton = (ToggleButton) inflate.findViewById(b.ʽॱ);
        toggleButton.setText(keywordInfo.ॱ());
        toggleButton.setTextOn(keywordInfo.ॱ());
        toggleButton.setTextOff(keywordInfo.ॱ());
        toggleButton.setClickable(false);
        return inflate;
    }

    public LayoutParams ˋ(View view) {
        LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LayoutParams(-2, -2);
        }
        layoutParams.bottomMargin = (int) ContentManager.getInstant().getContext().getResources().getDimension(a.ᐝ);
        return layoutParams;
    }

    public void ॱ(chy o_chy) {
        this.ॱˊ = o_chy;
    }

    private void ˋ() {
        if (this.ᐝ != null) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.ᐝ.getLayoutParams();
            layoutParams.height = 0;
            this.ᐝ.setLayoutParams(layoutParams);
        }
    }
}
